#include <iostream>
#include <assert.h>
#include <qbytearray.h>
#include <tws_debugging.h>
#include "xinfomatheadparser.h"

#define _DEBUG_HEAD_

XInfomatHeadParser::XInfomatHeadParser()
{
    memset (&m_configHead, 0x00, sizeof(m_configHead));
}

XInfomatHeadParser::~XInfomatHeadParser()
{
}

void XInfomatHeadParser::getHeadData(QByteArray in_datagram)
{
    char* tmpdata = new char[sizeof(STInfomatConfigHead)];
    memcpy(tmpdata, in_datagram.data(), sizeof(STInfomatConfigHead));
	STInfomatConfigHead* tmpHeadData = reinterpret_cast<STInfomatConfigHead*> (tmpdata);
	memcpy(&m_configHead, tmpHeadData,sizeof(STInfomatConfigHead));
	assert(INFOMAT_CONFIG_PROTOCOL == m_configHead.protocol);

#ifdef _DEBUG_HEAD_
    DEBUG("protocol : %02x", m_configHead.protocol);
    DEBUG("type     : %02d", m_configHead.type);
    DEBUG("size     : %02d", m_configHead.size);
    DEBUG("result   : %02d", m_configHead.result);
    DEBUG("command  : %02d", m_configHead.command);
#endif
	if (NULL != tmpdata )
	{
		delete tmpdata;
		tmpdata = NULL;
	}
}

uint8_t XInfomatHeadParser::getHeadProtocol() const
{
    return m_configHead.protocol;
}

uint8_t XInfomatHeadParser::getHeadType() const
{
    return m_configHead.type;
}

uint16_t XInfomatHeadParser::getHeadSize() const
{
    return m_configHead.size;
}

uint8_t XInfomatHeadParser::getHeadResult() const
{
    return m_configHead.result;
}

uint8_t XInfomatHeadParser::getHeadCommand() const
{
    return m_configHead.command;
}
